package com.jason.learn.apiproject.service;

import com.jason.learn.apiproject.mapper.OrderMapper;
import com.jason.learn.apiproject.mapper.ProductMapper;
import com.jason.learn.common.AbstractBaseService;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderService extends AbstractBaseService {
    @Autowired
    OrderMapper orderMapper;

    @Autowired
    ProductMapper productMapper;

    @Override
    public void process() {
        ((OrderService) AopContext.currentProxy()).transactionStep();
    }

    @Transactional
    public void transactionStep(){
        orderMapper.saveNewOrder();
        productMapper.updateStorage(1L);
        throw  new RuntimeException("test rollback");
    }
}
